package com.qf.boot2302.controller;

import com.qf.boot2302.entity.Car;
import com.qf.boot2302.entity.User;
import com.qf.boot2302.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("/test")
public class TestController {

    // 注意，Value注解中的写法，是${配置文件中的key}
    @Value("${qf.username}")
    private String username;

    @Autowired
    Car car;

    @Autowired
    User user;

    @RequestMapping("/test4")
    public ResultVo test4(HttpServletRequest request){
        String contextPath = request.getServletContext().getRealPath("/");
        return ResultVo.ok(1,"ok",contextPath);
    }

    @RequestMapping("/test3")
    public ResultVo test3() throws Exception {
        System.out.println(user);
        return ResultVo.ok(1, "ok", user);
    }

    @RequestMapping("/test2")
    public ResultVo test2() throws Exception {
        System.out.println(car);
        return ResultVo.ok(1, "ok", car);
    }

    @RequestMapping("/test1")
    public ResultVo test1() throws Exception {
        System.out.println(username);
//        byte[] bytes = username.getBytes("utf-8");
//        String s = new String(bytes, "utf-8");
//        System.out.println(s);
        return ResultVo.ok(1, "ok", username);
    }
}
